
from unittest import TestCase

from stream.mockable import mockable

def MockableTest(TestCase):
    def test(self):
        DEFAULT = 10
        MOCKED = 5
        @mockable
        def myfunc():
            return DEFAULT

        self.assertEqual(myfunc(), DEFAULT)

        def another_func():
            return MOCKED

        myfunc.mock(another_func)

        self.assertEqual(myfunc(), MOCKED)

        myfunc.reset()

        self.assertEqual(myfunc(), DEFAULT)

    def testWithArgs(self):
        DEFAULT = 10
        MOCKED = 5
        @mockable
        def myfunc(x):
            return x

        self.assertEqual(myfunc(DEFAULT), DEFAULT)

        def another_func(*args, **kwargs):
            return MOCKED
        myfunc.mock(another_func)

        self.assertEqual(myfunc(DEFAULT), MOCKED)
